#include "wrap.h"

// this is a client

#define MAXSIZE 4096
#define SERV_PORT 8888

void client(char *argv){
	int ret, clit_fd;
	char buf[MAXSIZE];
	struct sockaddr_in serv_addr;

	// 1. Create a socket
	clit_fd = Socket(AF_INET, SOCK_STREAM, 0);

	// 2. connect
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_port = htons(SERV_PORT);
	inet_pton(AF_INET, argv,(struct in_addr*)&serv_addr.sin_addr.s_addr);
	
	Connect(clit_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

	while(1){
		bzero(buf, MAXSIZE);
		fgets(buf,sizeof(buf), stdin);
		Write(clit_fd, buf, MAXSIZE);
		ret = Read(clit_fd, buf, MAXSIZE);
		Write(STDOUT_FILENO, buf, ret);
	}

	close(clit_fd);


}

int main(int argc, char *argv[]){
	client(argv[1]);
}
